//============================================================================
// Name        : Index.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Index Parser Versao mais que beta
//============================================================================
#include "ManualHash.h"
#include "IndexParser.h"
#include "IndexTable.h"

#include <iostream>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string>
#include <sstream>
using namespace std;

int main(int argc, char* argv) {
	
	DIR *dp;
	struct dirent *ep;
	string curDir="";
	string baseDir = "/work/google/crawler/Crawler/Debug/";
	string auxBaseDir = baseDir;
	IndexParser::fillConvMap();
	uint md5File;
	
	dp = opendir(auxBaseDir.append(argv[0]));
	if( dp != NULL)
	{
		while (ep = readdir(dp)) {
			curDir.append(ep->d_name);
			if(curDir != "." && curDir !="..") {
				baseDir = auxBaseDir.append(argv[0]);
				string s = baseDir.append(curDir);
				cout << "$$$$$$: " << s << endl;				
				IndexParser::getTextFromPage(s,curDir);
				cout << "sai" << endl;}
			curDir="";
		}
		closedir(dp);
	} 
	
	/*ifstream input;
	input.open("/work/abstract.rsm",ios::in);
	
	WordCounterTable counterTable;
	IndexParser::getIndexTableSize(&input,&counterTable);
	
	ofstream out_counter;
	out_counter.open("/work/WordCounter.txt", ios::out);
	counterTable.saveWordCounterTable(&out_counter);
	out_counter.close();
	
	ifstream in_counter;
	in_counter.open("/work/WordCounter.txt", ios::in);
	IndexTable index;
	index.IniciarTable(&in_counter);
	input.close();
	input.open("/work/abstract.rsm",ios::in);
	IndexParser::getWordsFromText(&input,&index);
	ofstream of;
	of.open("/work/finalTable.txt", ios::out);
	index.SalvarTable(&of);
	of.close(); */
	
	return 0;	
}
